package org.vogelsk.blue.app;

import org.vogelsk.blue.gui.BlueSurfaceView;

/**
 * 
 * This class defines thread that, while it is running, updates the game elements status, 
 * and notifies game custom SurfaceView to redraw.
 * @author dejan.dosic
 *
 */
public class GameThread extends Thread {
	

	private boolean running;
	private BlueSurfaceView gameView;

	public GameThread(BlueSurfaceView view) {
		gameView = view;
	}

	@Override
	public void run() {


		while (running == true) {
			if (gameView.getGameEngine() != null
					&& gameView.getGameEngine().isInGame()
					&& !gameView.getGameEngine().isPaused()) {
				gameView.getGameEngine().checkCollision();
				gameView.getGameEngine().checkFire();
				
				gameView.postInvalidateDelayed (10);}
				try {
					sleep(40);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			

		}
		
	}

	public boolean isRunning() {
		return running;
	}

	public void setRunning(boolean running) {
		this.running = running;
	}
}
